<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	Integer calltype = (Integer) session.getAttribute("calltype");
	Integer overdraft = (Integer) session.getAttribute("overdraft");
	String id = (String) session.getAttribute("id");
	String username = (String) session.getAttribute("username");
	String password = (String) session.getAttribute("password");
	String pic = (String) session.getAttribute("pic");
	String adid = (String) session.getAttribute("adid");
	String pid = (String) session.getAttribute("pid");
	String email = (String) session.getAttribute("email");
	String freeroute = (String) session.getAttribute("freeroute");
	String regimoney = (String) session.getAttribute("regimoney");
	String sqappkey =(String) session.getAttribute("sqappkey");
	String agentlogo =(String) session.getAttribute("agentlogo");
	String parentid =(String) session.getAttribute("parentid");
	String shopid =(String) session.getAttribute("shopid");
	Integer adminUsergrade =(Integer) session.getAttribute("adminUsergrade");
	java.math.BigDecimal aliprofitratio = (java.math.BigDecimal) session.getAttribute("aliprofitratio");
	java.math.BigDecimal dkbl = (java.math.BigDecimal) session.getAttribute("dkbl");
	java.lang.Boolean isalipay = (java.lang.Boolean) session.getAttribute("isalipay");
	java.lang.Boolean nextagent = (java.lang.Boolean) session.getAttribute("nextagent");
	java.lang.Boolean isprofit = (java.lang.Boolean) session.getAttribute("isprofit");
	java.lang.Boolean isaliprofit = (java.lang.Boolean) session.getAttribute("isaliprofit");
	java.lang.Boolean addcard = (java.lang.Boolean) session.getAttribute("addcard");
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>
<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- Select2 -->
<link href="<%=basePath%>vendors/select2/dist/css/select2.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
</head>

<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">
					<div class="clearfix"></div>
					<br />
				</div>
			</div>

			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left">
							<h3>账户信息</h3>
						</div>


					</div>
					
			
					<div class="clearfix"></div>

					<div class="row">
						<div class="col-md-12 col-sm-12 col-xs-12">
							<div class="x_panel">
								<div class="x_title">
									<h2>修改账户信息</h2>

									<div class="clearfix"></div>
								</div>
								<div class="x_content">

									<form name="myForm" class="form-horizontal form-label-left" novalidate 
						                  method= "post" enctype ="multipart/form-data" id="formUpload" > 

										<p>
											请谨慎修改相关信息，如有修改错误请及时
											<code>联系客服</code>
											以帮助您完成相关配置
										</p>
										<span class="section">基本信息</span>
										<div class="item form-group" style="display:none">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">id<span class="required"></span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="id" name="id" class="form-control col-md-7 col-xs-12"
													type="text" value="${id}">
											</div>
										</div>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">商户账号 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" name="name"
													placeholder="例如：随便打" required="required" type="text"
													value="${username}" id="username" disabled>
											</div>
										</div>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">登陆密码 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" name="name"
													placeholder="例如：24677111" required="required" type="text"
													value="${password}" id="password">
											</div>
										</div>
										
										<c:if test="${adminUsergrade == 0}">
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">所属代理商 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" name="name"
													placeholder="例如：24677111" required="required" type="text"
													value="${parentid}" id="parentid">
											</div>
										</div>
										</c:if>
										<c:if test="${adminUsergrade == 0 ||adminUsergrade == 1}">
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">所属商家 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" name="name"
													placeholder="例如：24677111" required="required" type="text"
													value="${shopid}" id="shopid">
											</div>
										</div>
										</c:if>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">费率 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="freeroute">
													<option value="${freeroute}" selected="selected">${freeroute}</option>
													<c:forEach items="${freeroutes}" var="s" varStatus="z">
														<option value="${s.name}">${s.name}</option>
													</c:forEach>
												</select>
											</div>
										</div>
										<div class="item form-group">

											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name" id="isalipayLaybel">线上支付<span
												class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="isalipay">
													<c:if test="${isalipay ==true }">
														<option value="true" selected="selected">允许</option>
														<option value="false">不允许</option>
													</c:if>
													<c:if test="${isalipay ==false }">
														<option value="true">允许</option>
														<option value="false" selected="selected">不允许</option>
													</c:if>

												</select>
											</div>
										</div>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">开设下级商户 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="nextagent">
													<c:if test="${nextagent ==true }">
														<option value="true" selected="selected">允许</option>
														<option value="false">不允许</option>
													</c:if>
													<c:if test="${nextagent ==false }">
														<option value="true">允许</option>
														<option value="false" selected="selected">不允许</option>
													</c:if>
												</select>
											</div>
										</div>
										
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">空中充值权限 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="airrecharge">
													<c:if test="${airrecharge ==1 }">
														<option value="1" selected="selected">允许</option>
														<option value="0">不允许</option>
													</c:if>
													<c:if test="${airrecharge ==0 }">
														<option value="1">允许</option>
														<option value="0" selected="selected">不允许</option>
													</c:if>
												</select>
											</div>
										</div>
										<c:if test="${adminUsergrade == 0}">
											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12"
													   for="name">财务信息权限 <span class="required">*</span>
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<select class="form-control" id="theme">
														<c:if test="${theme =='1' }">
															<option value="1" selected="selected">允许</option>
															<option value="0">不允许</option>
														</c:if>
														<c:if test="${theme =='0' }">
															<option value="1">允许</option>
															<option value="0" selected="selected">不允许</option>
														</c:if>
													</select>
												</div>
											</div>
										</c:if>
					                    <div class="item form-group" >
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">代理商LOGO <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12"
													 id="file" name="file" required="required" type="file"
													placeholder="请先上传图片" form="formUpload">
												<input id="agentlogo" name="agentlogo" class="form-control col-md-7 col-xs-12"
												    style="display:none" type="text" value="${agentlogo}">
											</div>
										</div>
					
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">通话引擎 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="calltype" onchange="show(this)">
													<option value="1" <c:if test="${calltype == 1}">selected="selected"</c:if>>SBDJH引擎</option>
													<option value="2" <c:if test="${calltype == 2}">selected="selected"</c:if>>SBDMY引擎</option>
													<option value="3" <c:if test="${calltype == 3}">selected="selected"</c:if>>SBDZP引擎</option>
													<option value="4" <c:if test="${calltype == 4}">selected="selected"</c:if>>SBDST引擎</option>
													<option value="5" <c:if test="${calltype == 5}">selected="selected"</c:if>>SBDCP引擎</option>
													<option value="6" <c:if test="${calltype == 6}">selected="selected"</c:if>>XGJCP引擎</option>
													<option value="7" <c:if test="${calltype == 7}">selected="selected"</c:if>>BCJH引擎</option>
													<option value="8" <c:if test="${calltype == 8}">selected="selected"</c:if>>XGJZP引擎</option>
													<option value="9" <c:if test="${calltype == 9}">selected="selected"</c:if>>SBDJHOLD引擎</option>
													<option value="10" <c:if test="${calltype == 10}">selected="selected"</c:if>>SBDJHCUSTOM引擎</option>
													<option value="11" <c:if test="${calltype == 11}">selected="selected"</c:if>>SBDSC引擎</option>
													<option value="12" <c:if test="${calltype == 12}">selected="selected"</c:if>>12号引擎</option>
													<option value="13" <c:if test="${calltype == 13}">selected="selected"</c:if>>13号引擎</option>
													<option value="14" <c:if test="${calltype == 14}">selected="selected"</c:if>>14号引擎</option>
												</select>
											</div>
										</div>

										<div class="item form-group" id="jhid" style="display: none">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												   for="name">JHAPP用户名 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="jhappid" class="form-control col-md-7 col-xs-12"
													   name="jhappid" placeholder="例如：张三" required="required"
													   type="text" value="${jhappid}">
											</div>
										</div>
										<div class="item form-group" id="jhkey" style="display: none">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												   for="name">JHAPP密码 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="jhappkey" class="form-control col-md-7 col-xs-12"
													   name="jhappkey" placeholder="例如：张三" required="required"
													   type="text" value="${jhappkey}">
											</div>
										</div>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">负责人 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" name="name"
													placeholder="例如：张三" required="required" type="text"
													value="${email}" id="email">
											</div>
										</div>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">ADID </label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" name="name"
													placeholder="例如：145910000"
													type="text" value="${adid}" id="adid">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">PID </label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" name="name"
													placeholder="例如：mm_101082177_39184040_145910000"
													type="text" value="${pid}" id="pid">
											</div>
										</div>
										
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">需要分润<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="isprofit">
													<c:if test="${isprofit ==true }">
														<option value="true" selected="selected">允许</option>
														<option value="false">不允许</option>
													</c:if>
													<c:if test="${isprofit ==false }">
														<option value="true">允许</option>
														<option value="false" selected="selected">不允许</option>
													</c:if>
												</select>
											</div>
										</div>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">分润比例 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="dkbl" class="form-control col-md-7 col-xs-12"
													name="name" placeholder="例如：1.00" required="required"
													type="text" value="${dkbl}">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">支付分润<span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="isaliprofit">
													<c:if test="${isaliprofit ==true }">
														<option value="true" selected="selected">允许</option>
														<option value="false">不允许</option>
													</c:if>
													<c:if test="${isaliprofit ==false }">
														<option value="true">允许</option>
														<option value="false" selected="selected">不允许</option>
													</c:if>
												</select>
											</div>
										</div>

										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">支付分润比例 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="aliprofitratio"
													class="form-control col-md-7 col-xs-12" name="name"
													placeholder="例如：1.00" required="required" type="text"
													value="${aliprofitratio}">
											</div>
										</div>
										<c:if test="${adminUserId == '2f4ef68e-3732-4e0a-902a-00cab9da0576'}">
											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12"
													for="name">结算积分类型<span class="required">*</span>
												</label>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<select class="form-control" id="igtype">
														<c:if test="${igtype == 1}">
														<option value="1" selected="selected">按天数计算返积分万分之五</option>
														<option value="2">一次性返积分15%</option>
														</c:if>
														<c:if test="${igtype == 2}">
														<option value="1">按天数计算返积分万分之五</option>
														<option value="2" selected="selected" >一次性返积分15%</option>
														</c:if>
													</select>
												</div>
											</div>
										</c:if>
										<div class="ln_solid"></div>
										<div class="form-group">
											<div class="col-md-6 col-md-offset-3">
												<a type="submit" class="btn btn-primary"
													href="javascript:void(0)"
													onclick="history.back(-1);">取消</a>
												<input id="revise" type="button" class="btn btn-success"
													href="javascript:void(0)" value="修改">
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- /page content -->
			<!-- 上传图片并修改 -->
			<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
			<script type="text/javascript" >
			$('#revise').click(function () {
			 
			    var file = document.myForm.file.files[0];
			    var id = $("#id").val();
			    var agentlogo = $("#agentlogo").val();
			    
			    if(file != null || file != undefined){

					var fileName = file.name.substring(file.name.lastIndexOf(".")+1).toLowerCase();
					
					if(fileName !="jpg" && fileName !="jpeg" && fileName !="png"&& fileName !="gif" ){
						alert("只能上传.jpg  .png  .jpeg  .gif类型的文件!");
			            return;
					}
					
					
					
			    	 var fm = new FormData();
						
					    fm.append('file', file);
					    
					    $.ajax(
					        {
					            url: "<%=basePath%>layfile/uploadFile1",
					            type: 'POST',
					            data: fm,
					            contentType: false, //禁止设置请求类型
					            processData: false, //禁止jquery对DAta数据的处理,默认会处理
					            //禁止的原因是,FormData已经帮我们做了处理
					            success: function (result) {
					                //测试是否成功
					                //但需要你后端有返回值
					                ajaxPost(id,result.json);
					            }
					        }
					    );
			    }else{
			    	ajaxPost(id,agentlogo);
			    }
			});
            </script>
			
			<script type="text/javascript">
				//初始化下拉选项
				//费率部分
				function s() {
					var objSelectNow = document.getElementById("freeroute");
					var inner = "<option value='1'>1</option>";
					objSelectNow.innerHTML = inner;
					var objOption = document.createElement("OPTION");
					objOption.text = 2;
					objOption.value = 2;
					objSelectNow.options.add(objOption);
				}
			</script>
			<script>
				function show(obj){
					document.getElementById("jhid").style.display=(obj.value==10)?"":"none";
					document.getElementById("jhkey").style.display=(obj.value==10)?"":"none"
				}
			</script>
			<script type="text/javascript">
				//获取select中的选项以及value
				function testSelect() {
					var a = $("#freeroute").find("option:selected").val();
					alert(a);
				}
				// ajax 对象
				function ajaxObject() {
					var xmlHttp;
					try {
						// Firefox, Opera 8.0+, Safari
						xmlHttp = new XMLHttpRequest();
					} catch (e) {
						// Internet Explorer
						try {
							xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
						} catch (e) {
							try {
								xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
							} catch (e) {
								alert("您的浏览器不支持AJAX！");
								return false;
							}
						}
					}
					return xmlHttp;
				}
			
				// ajax post请求：
				function ajaxPost(id,agentlogo) {
					var username = $("#username").val();
					var password = $("#password").val();
					var pic = $("#pic").val();
					var adid = $("#adid").val();
					var pid = $("#pid").val();
					var email = $("#email").val();
					var dkbl = $("#dkbl").val();
					var parentid = $("#parentid").val();
					var shopid = $("#shopid").val();
					var freeroute = $("#freeroute").find("option:selected").val();
					var calltype = $("#calltype").find("option:selected").val();
					var isalipay = $("#isalipay").find("option:selected").val();
					var nextagent = $("#nextagent").find("option:selected").val();
					var airrecharge = $("#airrecharge").find("option:selected").val();
					var isprofit = $("#isprofit").find("option:selected").val();
					var isaliprofit = $("#isaliprofit").find("option:selected").val();
                    var theme = $("#theme").find("option:selected").val();
					var aliprofitratio = $("#aliprofitratio").val();
					var igtype = $("#igtype").val(); // 积分类型
					if (igtype == null) {
						igtype = 1;
					}
					var choose = 2;
					var jhappid = $("#jhappid").val();
					var jhappkey = $("#jhappkey").val();
					var ajax = ajaxObject();
					if(password == "" ||password == null){
						alert("密码不能为空！");
					}else if(username == "" ||username == null){
						alert("商户账号不能为空！");
					}else{
						ajax.open("post", "updateUsers?password=" + password +
								"&username=" + username +
								"&parentid=" + parentid +
								"&shopid=" + shopid +
								"&jhappid=" + jhappid +
								"&jhappkey=" + jhappkey +
								"&pic=" + pic +
								"&adid=" + adid +
								"&pid=" + pid +
								"&email=" + email +
								"&id=" + id +
								"&freeroute=" + freeroute +
								"&calltype=" + calltype +
								"&isalipay=" + isalipay +
								"&nextagent=" + nextagent +
								"&airrecharge=" + airrecharge +
								"&agentlogo=" + agentlogo +
								"&isprofit=" + isprofit +
                                "&theme=" + theme +
								"&aliprofitratio=" + aliprofitratio +
								"&dkbl=" + dkbl +
								"&igtype=" + igtype +
								"&isaliprofit=" + isaliprofit +
								"&choose="+choose, true);
							ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
							ajax.onreadystatechange = function() {
								if (ajax.readyState == 4) {
									if (ajax.status == 200) {
										var result = ajax.responseText;
										if (result == "success") {
											//请求成功
											alert("修改成功");
											location.href = "content_shangjiaguanli";
										} else {
											//请求成功
											alert(result);
											location.href = "content_shangjiaguanli";
										}
									} else {
										//请求失败
										alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
									}
								} else {
								}
							};
							ajax.send();
					}
					
				}
			</script>
		</div>
	</div>

	<!-- jQuery -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<!-- <script>
		$("#username").blur(function(){
			// 获取内容文本
			var username = $(this).val();
			// ajax
			$.ajax({
				url:"../admin/content_bousername",
				type:"post",
				dataType:"json",
				data:{"username":username},
				success:function(date){
					// 验证结果
					if(date.flag==1){
						alert("该商户账号已经存在，请重新输入！");
					}else{
						//商户账号可用
					}
				},error:function(){
					//未传入用户名
				}
			});
		});
	</script> -->
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
	<!-- validator -->
	<script src="<%=basePath%>vendors/validator/validator.js"></script>
	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>
	<!-- Select2 -->
	<script src="<%=basePath%>vendors/select2/dist/js/select2.full.min.js"></script>
</body>
</html>